using System;
using System.Collections.Generic;
using Rhizome.Contract.Visitor;
using Rhizome.Internal;

namespace Rhizome.Model.Visitor
{
	public abstract class ElementVisitorBase<TElement> : IVisitor where TElement : class, IElement
	{
		private void Process(IEnumerable<TElement> elements)
		{
			elements.ForEach(element => element.Visit(this));
		}

		protected void Process(IElement root)
		{
			Process(root.GetAllElements<TElement>());
		}

		void IVisitor.Accept(IElement element)
		{
			Accept((TElement)element);
		}

		protected abstract void Accept(TElement element);
	}
}